* @param string $name: path name beetween zip root and current dir (encoded in system codepage)
*/
function add_dir($completeFilename, $name) {
$name = str_replace("\\", "/", $name);
$encodedName=$this->encode_filename($name);
// Local file header
$fr = "\x50\x4b\x03\x04";// local file header signature
$fr .= "\x14\x00";// version needed to extract
$fr .= "\x00\x00";// general purpose bit flag
$fr .= "\x08\x00";// compression method
$time = getdate(filemtime($completeFilename));
$fr .= pack('vv',2048*$time['hours']+32*$time['minutes']+floor($time['seconds']/2),512*($time['year']-1980)+32*$time['mon']+$time['mday']); // MS-DOS formated modification time & date
$fr .= pack("V",0);// crc-32
$fr .= pack("V",0);// compressed size
$fr .= pack("V",0);// uncompressed size
$fr .= pack("v", strlen($encodedName) );// file name length
$fr .= pack("v", 0 );// extra field length
$fr .= $encodedName;// file name
/*
$fr .= pack("V", 0);
$fr .= pack("V", 0);
$fr .= pack("V", 0);
*/
/*
$fr .= pack("V",$crc); // crc-32
$fr .= pack("V",$c_len); // compressed size
$fr .= pack("V",$unc_len); // uncompressed size
$fr .= pack("v", strlen($encodedName)); // file name length
$fr .= pack("v", 0 ); // extra field length
$fr .= $encodedName; // file name
$fr .= $zdata; // compressed data
*/
$this->nbDatasec++;
$this->lenData+=strlen($fr);
if(!$this->downloadSpeedLimit){
echo $fr;
flush();
}
else{
$p=0;
$bufferSize=min(16384,$this->downloadSpeedLimit);
while ($p<strlen($fr)) {
if($p+$bufferSize>strlen($fr)) {
echo substr($fr,$p);
$this->speedLimit->addData(strlen($fr)-$p);
}
else{
echo substr($fr,$p,$bufferSize);
$this->speedLimit->addData($bufferSize);
}
flush();
$p+=$bufferSize;
}
}
$new_offset = $this->lenData;
// Central directory header
$cdrec = "\x50\x4b\x01\x02"; // local file header signature
$cdrec .="\x14\x0b"; // version made by
$cdrec .="\x14\x00"; // version needed to extract
$cdrec .="\x00\x00"; // general purpose bit flag
$cdrec .="\x08\x00"; // compression method
$cdrec .= pack('vv',2048*$time['hours']+32*$time['minutes']+floor($time['seconds']/2),512*($time['year']-1980)+32*$time['mon']+$time['mday']); // MS-DOS formated modification time & date
$cdrec .= pack("V",0); // crc-32
$cdrec .= pack("V",0); // compressed size
$cdrec .= pack("V",0); // uncompressed size
$cdrec .= pack("v", strlen($encodedName) ); // file name length
$fr = "\x50\x4b\x03\x04";// local file header signature
$fr .= "\x14\x00";// version needed to extract
$fr .= "\x02\x00";// general purpose bit flag
$fr .= "\x08\x00";// compression method
$fr .= pack('vv',2048*$time['hours']+32*$time['minutes']+floor($time['seconds']/2),512*($time['year']-1980)+32*$time['mon']+$time['mday']); // MS-DOS formated modification time & date
$fr .= pack("V",$crc); // crc-32
$fr .= pack("V",$c_len); // compressed size
$fr .= pack("V",$unc_len); // uncompressed size
$fr .= pack("v", strlen($encodedName)); // file name length
$cdrec = "\x50\x4b\x01\x02";// local file header signature
$cdrec .="\x14\x0b";// version made by
$cdrec .="\x14\x00";// version needed to extract
$cdrec .="\x02\x00";// general purpose bit flag
$cdrec .="\x08\x00";// compression method
$cdrec .= pack('vv',2048*$time['hours']+32*$time['minutes']+floor($time['seconds']/2),512*($time['year']-1980)+32*$time['mon']+$time['mday']); // MS-DOS formated modification time & date